package com.yc.forum.servlet;

import com.yc.forum.dao.CategoryDao;
import com.yc.forum.dao.ProblemDao;
import com.yc.forum.dao.UserDao;
import com.yc.forum.util.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * 通过问题id获取问题信息，
 * 问题发布者信息
 *
 */
@WebServlet(name ="QueryOneProblemSomeMessagesByIdServlet",value = "/QueryOneProblemSomeMessagesByIdServlet.s")
public class QueryOneProblemSomeMessagesByIdServlet extends HttpServlet {
    ProblemDao problemDao=new ProblemDao();
    UserDao userDao=new UserDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取问题主键
        String problemId=req.getParameter("problemId");
        //通过主键获取问题信息
        Map<String,Object> problemMessages=problemDao.selectOneProblemById(problemId);
        //通过获取到的发布者账号获取发布者信息
        Map<String,Object> userMessages=userDao.queryUserMessagesByAccount(""+problemMessages.get("account"));
        //发布者昵称
        problemMessages.put("nickname",userMessages.get("nickname"));
        //获取单独的年月日
        Map<String,Object> date=Utils.dateToYearMonthDay(""+problemMessages.get("begintime"));
        //添加进入
        problemMessages.putAll(date);
        //将获取到的数据返回
        Utils.toJson(problemMessages,resp);
    }
}
